/// @tags:
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <numeric>

using std::cin, std::cout, std::endl;

namespace BlueQuantum {

constexpr int maxn = 10, maxm = 1e6 + 5, maxnum = 10;

typedef unsigned long long ll;

bool a[maxn];
int x[maxm];
ll mul[maxm];

struct Bigint {
  int num[maxnum], len;
  inline Bigint& operator*=(int x) {
    for (int i = 1; i <= len; i++) num[i] *= x;
    for (int i = 1; i <= len; i++) {
      num[i + 1] += num[i] / 10000;
      num[i] %= 10000;
    }
    if (num[len + 1] != 0) ++len;
    return *this;
  }
  inline Bigint& operator/=(int x) {
    memset(tmp, 0, sizeof(tmp));
    int tmplen = len, r = 0;
    while (len > 0 && num[len] == 0) len--;
    bool flag = false;
    for (int i = len; i; i--) {
      r = r * 10000 + num[i];
      tmp[i] = r / x;
      if (tmp[i] == 0 && !flag)
        tmplen--;
      else
        flag = true;
      r %= x;
    }
    memcpy(num, tmp, sizeof(tmp));
    len = tmplen;
    return *this;
  }
  inline bool operator<(const Bigint& rhs) const {
    if (len != rhs.len)
      return len < rhs.len;
    else {
      for (int i = len; i; --i) {
        if (num[i] != rhs.num[i]) return num[i] < rhs.num[i];
      }
      return false;
    }
  }
} mon, maxans;

int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1, tmp; i <= n; ++i) {
    cin >> tmp;
    a[tmp] = true;
  }
  for (int i = 1; i <= m; ++i) {
    cin >> x[i];
  }
  ll ans = 0;
  for (int i = 1; i <= m; ++i) {
    mul[i] = mul[i - 1] + 1ull * i * (i - 1);
  }
  int cnt = 0;
  for (int i = 1; i <= m; ++i) {
    if (a[x[i]]) {
      ++cnt;
    } else {
      ans += 1ull * cnt * (1 + cnt) / 2 * cnt - mul[cnt];
      cnt = 0;
    }
  }
  if (cnt != 0) {
    ans += 1ull * cnt * (1 + cnt) / 2 - mul[cnt];
  }
  cout << ans;
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("A.in", "r", stdin);
  freopen("A.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
